package com.fjh.springboot_01.mapper;

import com.fjh.springboot_01.pojo.ChatMsg;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import java.util.List;

@Mapper
public interface MessageMapper {

    @Insert("INSERT INTO chat_msg (senduserid, receiveuserid, sendtext, sendtime, msgtype) " +
            "VALUES (#{sendUserId}, #{receiveUserId}, #{sendText}, NOW(), #{msgType})")
    void saveMessage(ChatMsg chatMsg);

    @Select("SELECT * FROM chat_msg " +
            "WHERE (senduserid = #{userId} AND receiveuserid = #{friendId}) " +
            "OR (senduserid = #{friendId} AND receiveuserid = #{userId}) " +
            "ORDER BY sendtime DESC " +
            "LIMIT #{offset}, #{pageSize}")
    List<ChatMsg> getChatHistory(String userId, String friendId, int offset, int pageSize);
}
